package com.yami.shop.mystery.multishop.controller;

import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.mystery.common.dto.ProdCompoundDto;
import com.yami.shop.mystery.common.service.CompoundServer;
import com.yami.shop.mystery.common.vo.CompoundVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商品合成Controller
 */
@RestController
@RequestMapping("/platform/compound")
public class CompoundController {

    @Autowired
    private CompoundServer spuCompoundServer;

    @GetMapping("getList")
    @Operation(summary = "获取合成列表")
    public ServerResponseEntity<PageVO<CompoundVo>> getList(@Valid PageDTO pageDTO, ProdCompoundDto spuCompoundDTO) {
        return ServerResponseEntity.success(spuCompoundServer.getList(pageDTO,spuCompoundDTO));
    }


    @PostMapping("saveSpuCompound")
    @Operation(summary = "保存SpuCompound")
    public ServerResponseEntity<Void> saveSpuCompound(@RequestBody CompoundVo spuCompoundDTO) {
        spuCompoundServer.saveSpuCompound(spuCompoundDTO);
        return ServerResponseEntity.success();
    }

    @PostMapping("updateSpuCompound")
    @Operation(summary = "修改SpuCompound")
    public ServerResponseEntity<Void> updateSpuCompound(@RequestBody CompoundVo spuCompoundDTO) {
        spuCompoundServer.updateSpuCompound(spuCompoundDTO);
        return ServerResponseEntity.success();
    }

    @GetMapping("getCompoundDetail")
    @Operation(summary = "获取Compoud详情")
    public ServerResponseEntity<CompoundVo> getCompoundDetail(int compoundId){
        return ServerResponseEntity.success(spuCompoundServer.getDetail(compoundId));
    }

    @GetMapping("deleteSpuCompound")
    @Operation(summary = "删除SpuCompound")
    public ServerResponseEntity<Void> deleteSpuCompound(@RequestParam int id) {
        spuCompoundServer.deleteSpuCompound(id);
        return ServerResponseEntity.success();
    }

    @GetMapping("updateStatus")
    @Operation(summary = "合成上下架")
    public ServerResponseEntity<Void> updateStatus(@RequestParam int id,
                                                   @RequestParam int status) {
        spuCompoundServer.updateStatus(id,status);
        return ServerResponseEntity.success();
    }


}
